#! /bin/bash
# 获取电池电量

bat_icon() {
    if   [ "$bat_text" -ge 95 ]; then bat_icon="";
    elif [ "$bat_text" -ge 90 ]; then bat_icon="";
    elif [ "$bat_text" -ge 80 ]; then bat_icon="";
    elif [ "$bat_text" -ge 70 ]; then bat_icon="";
    elif [ "$bat_text" -ge 60 ]; then bat_icon="";
    elif [ "$bat_text" -ge 50 ]; then bat_icon="";
    elif [ "$bat_text" -ge 40 ]; then bat_icon="";
    elif [ "$bat_text" -ge 30 ]; then bat_icon="";
    elif [ "$bat_text" -ge 20 ]; then bat_icon="";
    elif [ "$bat_text" -ge 10 ]; then bat_icon="";
    else bat_icon=""; fi
}

update() {
    icon_color="^c#3B001B^^b#4865660x88^"
    text_color="^c#3B001B^^b#4865660x99^"

    # Change BAT1 to whatever your battery is identified as. Typically BAT0 or BAT1
    bat_text=$(cat /sys/class/power_supply/BAT0/capacity)
    bat_status=$(cat /sys/class/power_supply/BAT0/status)

    #if [ "$bat_status" = "Discharging" ]; then
    if [ "$bat_status" = "Not charging" ]; then
        charge_icon=" " && bat_icon
    else
        charge_icon=""&& bat_icon
    fi

    icon="$charge_icon$bat_icon"
    text="$bat_text"

    echo "$icon_color $icon $text_color$text"
}

update
